#ifndef _PACKETS_
#define	_PACKETS_

#include <cstring>
#include "Types.hpp"
#include <stdlib.h>

//Keep packet structure in alphabetic order
//All packets must be packed.

//Minimum possible size of a valid packet.
//2 bytes for packet size
//1 byte for code
//4 bytes for time
//0+ for data
#define MIN_PACKET_SIZE 7

#pragma pack(push, 1)

/** 
* Entity location information from the server.
*/
struct Packet_ServerEntityLocation {
    uint16_t client;
	byte direction;
    float x;
    float y;
};
#pragma pack(pop)

#pragma pack(push, 1)
/** 
* Packet containing entity information.
*/
struct Packet_EntityState{
	byte direction;
	uint16_t index;
	char script[OBJECT_SCRIPT_LENGTH];
    float x;
    float y;
};
#pragma pack(pop)

#define CHAT_MESSAGE_LEN 60

#pragma pack(push, 1)
/** 
 * Chat message.
 * A message from client 255 is reserved as a Server message.
 */
struct Packet_ChatMessage{
    byte client;
    char message[CHAT_MESSAGE_LEN + 1];
};
#pragma pack(pop)

#define CLIENT_NAME_LEN 20

#pragma pack(push, 1)
/** 
* Packet containing client information.
*/
struct Packet_ClientState{
    byte client;
	byte direction;
	char name[CLIENT_NAME_LEN + 1];
    float x;
    float y;
};
#pragma pack(pop)

#pragma pack(push, 1)
/** 
* Change client name.
*/
struct Packet_ClientRename{
    byte client;
    char name[CLIENT_NAME_LEN + 1];
};
#pragma pack(pop)

#pragma pack(push, 1)
/** 
* Packet containing the current state of the game.
*/
struct Packet_GameState{
    byte maxClients;
};
#pragma pack(pop)

#endif